<?php
/**
 * PHP Mailer 接口.
 *
 * $Id: mail.php 9 2009-04-26 06:35:12Z bole.Chen $
 **/

require_once ROOT.'includes'.DS.'classes'.DS.'phpmailer'.DS.'class.phpmailer.php';

class mail extends phpmailer {

    // Set default variables for all new objects
    var $From       = "loopo.cn@gmail.com";
    var $FromName   = "LooPo乐铺";
    var $Host       = "";
    var $Mailer     = "smtp";   // Alternative to IsSMTP()
    //var $WordWrap   = 75;

    var $CharSet    = 'utf-8';

    // Smtp Auth
    var $SMTPAuth   = true;
    var $Username   = '';
    var $Password   = '';
    //var $SMTPDebug  = true;

    function mail() {
        $this->AddReplyTo('loopo.cn@gmail.com', 'LooPo.cn');
    }
}

class gmail extends mail {

    // Set default variables for all new objects
    var $Host       = "ssl://smtp.gmail.com";
    var $Port       = 465;
    var $Encoding   = 'base64';

    // Smtp Auth
    var $Username   = '';
    var $Password   = '';

    function gmail() {
        $this->mail();
    }

    /**
     * Initiates a connection to an SMTP server.  Returns false if the
     * operation failed.
     * @access private
     * @return bool
     */
    function SmtpConnect() {
        if($this->smtp == NULL) { $this->smtp = new SMTP(); }

        $this->smtp->do_debug = $this->SMTPDebug;
        $hosts = explode(";", $this->Host);
        $index = 0;
        $connection = ($this->smtp->Connected());

        // Retry while there is no connection
        while($index < count($hosts) && $connection == false)
        {
            if(strstr($hosts[$index], ":"))
                list($host, $port) = explode(":", $hosts[$index]);
            else
            {
                $host = $hosts[$index];
                $port = $this->Port;
            }

            //Modify by Fwolf @ 2006-4-14, to enable ssl mail connection
            $host = $this->Host;
            $port = $this->Port;

            if($this->smtp->Connect($host, $port, $this->Timeout))
            {
                if ($this->Helo != '')
                    $this->smtp->Hello($this->Helo);
                else
                    $this->smtp->Hello($this->ServerHostname());

                if($this->SMTPAuth)
                {
                    if(!$this->smtp->Authenticate($this->Username,
                                                  $this->Password))
                    {
                        $this->SetError($this->Lang("authenticate"));
                        $this->smtp->Reset();
                        $connection = false;
                    }
                }
                $connection = true;
            }
            $index++;
        }
        if(!$connection)
            $this->SetError($this->Lang("connect_host"));

        return $connection;
    }
}
?>
